import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler

pd.set_option("display.width",500)
pd.set_option("display.max_rows",500)
pd.set_option("display.max_columns",500)

df=pd.read_csv("./Bike-Sharing-Dataset/day.csv")
print(df.head())
print(df.shape)
print(df.info())

'''对类别特征进行独热编码'''
categorical_features=['season','mnth','weekday','weathersit']
'''数据类型变为object，才能被get_dummies处理'''
for col in categorical_features:
    df[col]=df[col].astype('object')

x_train_cat=df[categorical_features]
x_train_cat=pd.get_dummies(x_train_cat)
print(x_train_cat.head())

'''对数值特征进行标准化，去量纲'''
mn_x=MinMaxScaler()
numerical_features=['temp','atemp','hum','windspeed']
temp=mn_x.fit_transform(df[numerical_features])

x_train_num=pd.DataFrame(data=temp,columns=numerical_features,index=df.index)
print(x_train_num.head())

'''连接类别特征和数字特征'''
x_train=pd.concat([x_train_cat,x_train_num,df['holiday'],df['workingday']],axis=1,ignore_index=False)
print(x_train.head())
print(x_train.shape)

FE_train=pd.concat([x_train,df['yr'],df['cnt']],axis=1)
FE_train.to_csv('FE_day.csv',index=False)
print(FE_train.head())
print(FE_train.info())